﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace WRS
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class Read : Page
    {
        private Queue<string> Picture = new Queue<string>();
        private Queue<string> Picture1 = new Queue<string>();
        private string title1;
        private int score;
        private string directory = "ms-appx:/pictures/";
        private string fileType = ".png";
        public Read()
        {
            this.InitializeComponent();
            score = 0;
            Picture.Enqueue("cat");
            Picture.Enqueue("dog");
            Picture.Enqueue("rat");
            Picture.Enqueue("cat");
            Picture1.Enqueue("bat");
            Picture1.Enqueue("cap");
            Picture1.Enqueue("net");
            Picture1.Enqueue("cat");
            readWord();
        }

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            var title = e.Parameter;
            title1 = title.ToString();
        }

        private void btnForward_Click(object sender, RoutedEventArgs e)
        {
            this.Frame.Navigate(typeof(Spelling), title1);
        }

        private void btnBackward_Click(object sender, RoutedEventArgs e)
        {
            this.Frame.Navigate(typeof(BlankPage));
        }

        private void readWord()
        {
            try
            {
                string pic = "";
                if (title1 == "Animals")
                {
                    pic = Picture.Dequeue();
                    audioPlayer.Source = new Uri("ms-appx:/Audio/PleaseSayTheWord.mp3", UriKind.Absolute);
                    picture.Visibility = Visibility.Collapsed;
                    //picture.Source = new BitmapImage(new Uri(directory + pic + fileType, UriKind.Absolute));
                    audioPlayer.Play();
      

                }
                else if (title1 == "Sports")
                {
                    pic = Picture1.Dequeue();
                    picture.Visibility = Visibility.Visible;
                    audioPlayer.Source = new Uri("ms-appx:/Audio/PleaseSayTheWord.mp3", UriKind.Absolute);
                    picture.Source = new BitmapImage(new Uri(directory + pic + fileType, UriKind.Absolute));
                    audioPlayer.Play();
                }
                txblkWord.Text = pic;
            }
            catch (Exception ex)
            { }

        }

        private void btnNext_Click(object sender, RoutedEventArgs e)
        {
            readWord();
            score += 10;
            txtScore.Text = "Score: " + score.ToString();
        }

        private void Grid_Loaded_1(object sender, RoutedEventArgs e)
        {       
            txtTitle.Text = title1;
            readWord();
        }
    }
}
